Skip to content

Add observability: token tracking, error logging, action audit trail#22

Open
martinjms wants to merge 3 commits intomainfrom
feature/observability
Open

Add observability: token tracking, error logging, action audit trail#22
martinjms wants to merge 3 commits intomainfrom
feature/observability

Conversation

@martinjms
Copy link
Copy Markdown
Contributor

Summary

  • Structured JSONL logger used by all components (brain, kernel, channels)
  • Tracks every API call with token counts, cost estimation, and advisor usage
  • Logs tool executions, errors, actions (commits, rollbacks, reloads), and messages
  • 3 new tools so the agent can query its own logs: log_cost_summary, log_search, log_errors
  • Daily-rotated log files in .state/logs/
  • 13 new tests (72 total, all passing)

Why this is first

Every unconscious process we build after this will automatically have observability. The agent can check its own costs, debug errors, and understand what happened during the day.

Test plan

  • Logger unit tests: API logging, tool logging, error logging, action logging, message logging
  • Cost estimation tests: Sonnet, Opus, Haiku pricing
  • Read/query tests: readLog, costSummary
  • All 72 existing tests pass
  • Manual: run the bot, check .state/logs/ for JSONL entries

Closes #21

🤖 Generated with Claude Code

martinjms and others added 3 commits April 11, 2026 19:42
New modules:
- logger.js: structured JSONL logger with cost estimation, used by all components
- tools/logs.js: 3 tools (log_cost_summary, log_search, log_errors) so the
  agent can query its own usage and debug issues

Wired into:
- Brain: logs every API call (tokens, cost, advisor usage, duration) and
  every tool execution (name, args, result, duration, errors)
- Kernel: logs auto-commits, rollbacks, verification pass/fail
- Webchat: logs inbound messages

Logs written to .state/logs/ as daily-rotated JSONL files.
Cost estimation built in for Sonnet, Opus, and Haiku pricing.

Closes #21

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Per-tool logs: each tool execution writes to both the aggregate
tools log and a dedicated tools-{name} log (e.g. tools-execute_shell).
Enables isolated debugging per tool across time.

Reasoning traces: heartbeat and cron cycles now capture the entire
brain conversation (text, tool calls, tool results) to traces/ logs.
You can reconstruct exactly what the agent thought and did in each
autonomous cycle, including partial traces on failure.

75 tests passing (3 new trace/per-tool tests).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Every execution context (heartbeat cycle, cron job, conversation turn)
gets a unique trace_id that flows through brain → API calls → tool calls.
This enables:

- log_cost_per_task: "heartbeat hb_1712880000_a cost $0.0234 (3 API calls)"
- Correlate all API calls and tool executions to the task that triggered them
- See exactly which heartbeat cycle was expensive and why

Also adds costByTrace() to the logger for aggregating costs by trace.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement observability: token tracking, error logging, and action audit trail

1 participant